package cn.masterj.springcloud.controller;


import cn.masterj.springcloud.CommonResult;
import cn.masterj.springcloud.entity.Payment;
import cn.masterj.springcloud.service.IPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author masterJ
 * @since 2020-04-03
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Autowired
    private IPaymentService paymentService;

    @GetMapping("/getById/{id}")
    public CommonResult getById(@PathVariable("id") Long id){
        Payment payment = paymentService.getById(id);
        if (payment != null){
            return new CommonResult(200,"查询数据成功", payment);
        }else {
            return new CommonResult(444, "没有查询到数据");
        }
    }

    @PostMapping("/create")
    public CommonResult create(@RequestBody Payment payment){
        boolean b = paymentService.save(payment);
        if (b){
            return new CommonResult(200,"插入成功", payment);
        }else {
            return new CommonResult(444, "插入失败");
        }
    }
}
